package com.kws.commercial.controller;

import com.github.pagehelper.PageInfo;
import com.kws.commercial.business.UploadFileBusiness;
import com.kws.commercial.dao.Info.QueryProjectFileInfo;
import com.kws.commercial.dao.Info.QueryProjectScheduleInfo;
import com.kws.commercial.dao.Rq.CreateProjectScheduleRq;
import com.kws.commercial.dao.Rq.UploadProjectScheduleFileRq;
import com.kws.commercial.service.CommercialProjectScheduleService;
import com.kws.common.core.domain.R;
import com.kws.system.api.domain.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * <b>CommercialProjectScheduleController</b>
 *
 * @description: CommercialProjectScheduleController <br>
 * @date: 2024/10/29 15:37 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "项目进度管理模块")
@RestController
public class CommercialProjectScheduleController {
    private static final Logger logger = LoggerFactory.getLogger(CommercialProjectScheduleController.class);

    @Autowired
    private CommercialProjectScheduleService commercialProjectScheduleService;

    @Autowired
    private UploadFileBusiness uploadFileBusiness;

    @ApiOperation("分页查询项目进度管理列表")
    @GetMapping("/query/projectSchedule/page")
    public R<PageInfo<QueryProjectScheduleInfo>> queryProjectSchedulePage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                          @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                          @RequestParam(required = false) String schemeName){
        PageInfo<QueryProjectScheduleInfo> pageInfo = commercialProjectScheduleService.queryProjectSchedulePage(pageNum,pageSize,schemeName);
        return R.ok(pageInfo);
    }

    @ApiOperation("创建项目")
    @PostMapping("/create/projectSchedule")
    public R createProjectSchedule(@RequestBody CreateProjectScheduleRq rq){
        boolean status = commercialProjectScheduleService.createProjectSchedule(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID查询详情")
    @GetMapping("/query/projectSchedule/byId")
    public R<QueryProjectScheduleInfo> queryProjectScheduleById(@RequestParam Long id){
        QueryProjectScheduleInfo info = commercialProjectScheduleService.queryProjectScheduleById(id);
        return R.ok(info);
    }

    @ApiOperation("根据ID查询项目文件附件列表")
    @GetMapping("/query/projectScheduleInfo/byId")
    public R<Map<String, List<QueryProjectFileInfo>>> queryProjectScheduleInfoById(@RequestParam Long id){
        Map<String, List<QueryProjectFileInfo>> fileMap = commercialProjectScheduleService.queryProjectScheduleInfoById(id);
        return R.ok(fileMap);
    }

    @ApiOperation("根据项目ID上传项目进度相关阶段文件")
    @PostMapping("/upload/projectScheduleInfo/byProjectQuotationId")
    public R<Map<String, List<QueryProjectFileInfo>>> uploadProjectScheduleInfoByProjectQuotationId(@RequestBody UploadProjectScheduleFileRq rq){
        Map<String, List<QueryProjectFileInfo>> fileMap = commercialProjectScheduleService.uploadProjectScheduleInfoByProjectQuotationId(rq);
        return R.ok(fileMap);
    }

    @ApiOperation("上传文件")
    @PostMapping("/upload/file")
    public R uploadFile(@RequestParam("file") MultipartFile file){
        String fileUrl = uploadFileBusiness.uploadFile(file);
        return R.ok(fileUrl);
    }
}
